package cn.lili.modules.payment.entity.dto;

import cn.hutool.core.util.StrUtil;
import cn.lili.common.vo.PageVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 微信进件搜索参数
 */
@Data
public class WechatApplymentSearchParams extends PageVO {


    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "起始日期")
    private String startDate;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "结束日期")
    private String endDate;

    @ApiModelProperty(value = "业务申请编号")
    String outRequestNo;
    @ApiModelProperty(value = "主体类型")
    String organizationType;

    @ApiModelProperty(value = "商户简称")
    String merchantShortname;


    public <T> QueryWrapper<T> queryWrapper() {
        QueryWrapper<T> wrapper = new QueryWrapper<>();

        //创建时间
        if (StrUtil.isNotBlank(startDate) && StrUtil.isNotBlank(endDate)) {
            wrapper.between("create_time", startDate, endDate);
        } else if (StrUtil.isNotBlank(startDate)) {
            wrapper.ge("create_time", startDate);
        } else if (StrUtil.isNotBlank(endDate)) {
            wrapper.le("create_time", endDate);
        }
        wrapper.eq(StrUtil.isNotBlank(outRequestNo), "out_request_no", outRequestNo);
        wrapper.eq(StrUtil.isNotBlank(organizationType), "organization_type", organizationType);
        wrapper.eq(StrUtil.isNotBlank(merchantShortname), "merchant_shortname", merchantShortname);
        return wrapper;
    }
}
